(function () {
    angular.module('app')
        .component('xxRecharge', {
            templateUrl: '/app/user/recharge/recharge.html',
            controller: ctrl
        });

    function ctrl($scope,$state,$stateParams,$mdDialog,userService,RechargeFactory,urlCnst) {
        var username = userService.username;
        $scope.assetRecharge = {
            'asset':1
        };
        $scope.assetBalance = userService['asset'];


        function getAsset(username) {
            function cb(err,res) {
                if (!err){
                    $scope.assetBalance = res['res']['asset'];
                    //console.log('test',dd,$scope.personInfo);
                }
            }
            RechargeFactory.getAsset(username,cb);
        }
        getAsset(username);

        // 数据(asset)是一个键值对,非直接的数字
        $scope.rechargeByUsername = function (asset) {
            console.log(asset);
            var username = $stateParams.username;
            function cb(err, res) {
                if (!err) {
                    urlCnst.notice('充值成功！');
                    getAsset(username);  // 刷新余额
                    console.log(err, res);
                }
            }
            RechargeFactory.rechargeByUsername(username, asset, cb);
        };
    }
})();
